﻿using System;
using System.Collections.Generic;
using System.Windows.Media;

namespace HDViewSL
{
	/// <summary>
	/// A custom tile source that uses an HD View image set to retrieve tiles.
	/// </summary>
	public class HDViewTileSource : MultiScaleTileSource
	{
		/// <summary>
		/// Constructs a new custom tile source from an HD View image set.
		/// </summary>
		/// <param name="imageSet">The HD View image set to use.</param>
		public HDViewTileSource(HDViewImageSet imageSet)
			: base(imageSet.PaddedWidth, imageSet.PaddedHeight, imageSet.TileWidth, imageSet.TileHeight, imageSet.TileOverlap)
		{
			this.ImageSet = imageSet;
		}

		/// <summary>
		/// The HD View image set used by this custom tile source.
		/// </summary>
		public HDViewImageSet ImageSet { get; private set; }

		/// <summary>
		/// Adds the URI for the specified tile to the given list.
		/// </summary>
		/// <param name="tileLevel">The tile's hierarchy level.</param>
		/// <param name="tilePositionX">The tile's horizontal position.</param>
		/// <param name="tilePositionY">The tile's vertical position.</param>
		/// <param name="tileImageLayerSources">The output list of tile URIs.</param>
		protected override void GetTileLayers(int tileLevel, int tilePositionX, int tilePositionY, IList<object> tileImageLayerSources)
		{
			Uri uri = this.ImageSet.GetTileUri(tileLevel, tilePositionX, tilePositionY);
			if (uri != null)
			{
				tileImageLayerSources.Add(uri);
			}
		}
	}
}
